package as3.component.ui
{
	
	import as3.component.Component;
	import as3.component.controls.Label;
	import as3.component.manager.ElementDragManager;
	import as3.component.manager.UIManager;
	
	import com.seaengine.GameConfig;
	import com.seaengine.constData.Enums;
	import com.seaengine.core.event.GlobalEvent;
	import com.seaengine.proxy.ItemProxy;
	import com.seaengine.resourcemanager.ResSystem;
	import com.seaengine.resourcemanager.loadtool.LoadUtils;
	import com.seaengine.util.DisplayObjectCopy;
	import com.seaengine.util.FilterUtil;
	import com.seaengine.valueobject.BaseItemVo;
	import com.seaengine.valueobject.ItemType;
	import com.seaengine.valueobject.VoType;
	
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.ColorMatrixFilter;
	import flash.filters.GlowFilter;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.text.TextFormatAlign;
	import flash.utils.ByteArray;
	import flash.utils.setTimeout;
	
	public class Element extends Component
	{
		public static const VO_CHANGE:String = 'vo_change'; /**vo change event*/


		private var _bg:DisplayObject;
		private var _fore:DisplayObject;

		private var _enabled:Boolean = true;
		private var _downP:Point;
		private var bgIconUrl:String;

		private var icon:Bitmap;
		public var vo:BaseItemVo;

		public var continerType:String = "";
		public var itemType:int;
		private var _index:int;
		/**数量小角标*/
		public var countLabel:Label;

		public var lock:DisplayObject;

		public var isLocking:Boolean = false;
		
		public var isStartUsing:Boolean = false;
		
		/**物品栏说明*/
		private var textLabel:Label;

		private var openCount:uint;

		private var okAlert:Boolean = false;
		
		private var loadUtils:LoadUtils;
		
		/**
		 * 是否需要显示数量下标 
		 */
		private var showCountLabel:Boolean = true;
		
		/**
		 * 是否可以拖动 
		 */
		private var dragAble:Boolean = true;
		

		public function Element(bg:String = "Item48Bg", okAlert:Boolean = false, textStr:String = "",showCount:Boolean = true,_dragAble:Boolean = true)
		{
			this.okAlert = okAlert;
			showCountLabel = showCount;
			dragAble = _dragAble;
			bgIconUrl = bg == "" ? "Item48Bg" : bg;
			super();
			doubleClickEnabled = true;
			icon = new Bitmap();
			countLabel = new Label();
			countLabel.color = 0xFFFFFF;
			countLabel.mouseEnabled = false;
			countLabel.mouseChildren = false;
			countLabel.width = 48;
			countLabel.height = 19;
			countLabel.algin = TextFormatAlign.RIGHT;
			countLabel.x = 0;
			countLabel.y = 33;
			addChild(icon);
			textLabel = new Label();
			textLabel.text = textStr;
			textLabel.color = 0x333333;
			textLabel.mouseEnabled = false;
			textLabel.mouseChildren = false;
			textLabel.algin = TextFormatAlign.RIGHT;
			textLabel.x = 8;
			textLabel.y = 15;
			textLabel.fontSize = 12;
			textLabel.bold = true;
			textLabel.filters = [new GlowFilter(0x000000, 1, 2, 2, 12, 1, false, false)];
			addChild(textLabel);
			loadUtils = new LoadUtils();
		}

		override protected function initUI():void
		{
			super.initUI();
			uiLibrary["bg"] = bgIconUrl;
			uiLibrary["fore"] = "Item48Over";
			lock = DisplayObjectCopy.copy(UIManager.defaultSkin.getUIByName("BagLock") as DisplayObject);
		}
		
		override protected function creatUI():void
		{
			super.creatUI();
			setSize(48,48);
		}

		override protected function initListener():void
		{
			super.initListener();
			addEnabledListener();
		}

		private function addEnabledListener():void
		{
			addEventListener(MouseEvent.ROLL_OVER, onRollOverHandler, false, 0, true);
			addEventListener(MouseEvent.ROLL_OUT, onRollOutHandler, false, 0, true);
			addEventListener(MouseEvent.DOUBLE_CLICK, onDoubleClickHandler, false, 0, true);
			addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler, false, 0, true);
		}

		private function removeEnabledListener():void
		{
			removeEventListener(MouseEvent.ROLL_OVER, onRollOverHandler);
			removeEventListener(MouseEvent.ROLL_OUT, onRollOutHandler);
			removeEventListener(MouseEvent.DOUBLE_CLICK, onDoubleClickHandler);
			removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
		}

		private function onRollOverHandler(evt:MouseEvent):void
		{
			if (enabled)
			{
				_fore.visible = true;
			}
		}

		private function onRollOutHandler(evt:MouseEvent):void
		{
			_fore.visible = false;
		}

		private function onDoubleClickHandler(evt:MouseEvent):void
		{
			if (enabled && vo)
			{
				switch (continerType)
				{
					case ElementContinerType.TYPE_BACKPACK_EQUIPMENT:
						if (ItemType.checkIsEquipment(vo.type))
						{
							if (wearEquipmentJudge(vo) == true)
							{
								if (vo.type == Enums.ITEM_TYPE_SPECIAL)
								{
									var temp:uint = getQiWuIndex();
									if (temp != 0)//穿奇物
									{
										ItemProxy.getInstance().exChangeItem(vo.category, vo.index, temp);
									}
								}
								else//穿装备
								{
									ItemProxy.getInstance().exChangeItem(vo.category, vo.index, ItemProxy.equipmentToType[vo.type]);
								}
							}
						}
						break;
					case ElementContinerType.TYPE_USER_EQUIPMENT:
					case ElementContinerType.TYPE_USER_WUQI:
					case ElementContinerType.TYPE_USER_JINNANG:
						var targteIndex:int = ItemProxy.getInstance().findEmptyIndex(VoType.EQUIPMENT, 20);
						if (targteIndex != -1)//脱装备
						{
							ItemProxy.getInstance().exChangeItem(vo.category, vo.index, targteIndex);
						}
						break;
					case ElementContinerType.TYPE_BACKPACK_DAOJU:
						break;
				}
			}
		}


		private function onMouseDownHandler(evt:MouseEvent):void
		{
			if (isLocking == false)
			{
				if (vo && icon.bitmapData && dragAble)
				{
					_downP = new Point(stage.mouseX, stage.mouseY);
					stage.addEventListener(MouseEvent.MOUSE_MOVE, onStageMoveHandler, false, 0, true);
					stage.addEventListener(MouseEvent.MOUSE_UP, onStageUpHandler, false, 0, true);
				}
			}
			else
			{
				removeEventListener(MouseEvent.ROLL_OUT, onRollOutHandler);
				var tempIndex:uint;
				switch (continerType)
				{
					case ElementContinerType.TYPE_BACKPACK_EQUIPMENT:
						tempIndex = ItemProxy.getInstance().equipmentOpenCount + 20;
						break;
					case ElementContinerType.TYPE_BACKPACK_DAOJU:
						tempIndex = ItemProxy.getInstance().daoJuOpentCount;
						break;
					case ElementContinerType.TYPE_BACKPACK_BAOSHI:
						tempIndex = ItemProxy.getInstance().baoShiOpenCount;
						break;
					case ElementContinerType.TYPE_BACKPACK_TASK:
						tempIndex = ItemProxy.getInstance().taskOpenCount;
						break;
				}
				openCount = index - tempIndex + 1;
			//	var panel:BackPackPanel = PanelManager.getInstance().getPanel(PanelType.BACKPACK_PANEL) as BackPackPanel;
//				for each (var _item:Element in panel.bagContent.itemList)
//				{
//					if (_item._index >= tempIndex && _item._index <= index)
//					{
//						if (_item.isLocking == true)
//						{
//							_item._fore.visible = true;
//						}
//					}
//					else
//					{
//						_item._fore.visible = false;
//					}
//				}
				//Alert.show("花费:" + (openCount * costYBPrice) + "元宝,开启" + openCount + "格子", Alert.OK | Alert.CANCEL, confirmHandler);
			}
		}
		

		private function confirmHandler(value:uint):void
		{
//			var panel:BackPackPanel = PanelManager.getInstance().getPanel(PanelType.BACKPACK_PANEL) as BackPackPanel;
//			for each (var _item:Element in panel.bagContent.itemList)
//			{
//				_item._fore.visible = false;
//			}
//			if (value == Alert.OK)
//			{
//				GlobalEventDispatcher.getInstance().addEventListener(GlobalEvent.OPEN_BACK_GRID_SCCESS, openBackGrid);
//				networkLogicProtocol.getInstance().requestOpenSolts(panel.bagContent.selelctIndex + 1, openCount);
//			}
//			addEventListener(MouseEvent.ROLL_OUT, onRollOutHandler);
		}

		private function openBackGrid(e:GlobalEvent):void
		{
			//updateGrid();
		}

		private function onStageMoveHandler(evt:MouseEvent):void
		{
			if (Math.abs(stage.mouseX - _downP.x) > 5 || Math.abs(stage.mouseY - _downP.y) > 5)
			{
				//trace("开始拖动了");
				vo.continerType = continerType;
				stage.removeEventListener(MouseEvent.MOUSE_MOVE, onStageMoveHandler);
				ElementDragManager.getInstance().beginDrag(icon, vo);
			}
		}

		private function onStageUpHandler(evt:MouseEvent):void
		{
			stage.removeEventListener(MouseEvent.MOUSE_MOVE, onStageMoveHandler);
			stage.removeEventListener(MouseEvent.MOUSE_UP, onStageUpHandler);
			_downP = null;
			if (evt.target == this)
			{
				ElementDragManager.getInstance().clearDrag();
				return;
			}
			var drageTarget:DisplayObject = ElementDragManager.getInstance().dragTarget;
			var drageProxy:BaseItemVo = BaseItemVo(ElementDragManager.getInstance().dragProxy);
			var dropTarget:Class = ElementDragManager.checkDropTarget(evt.target as DisplayObject);
//			if (drageTarget && drageProxy)
//			{
//				if (dropTarget == StorePanel) //拖动到商店上，表示要出售
//				{
//					ElementDragManager.getInstance().clearDrag();
//					Alert.show("确定要出售" + vo.name + "?", Alert.OK | Alert.CANCEL, sellHandler);
//					return;
//				}
//				else if (dropTarget == SkillsItem && (evt.target is SkillsIconManager) == false
//					&& vo.type == Enums.ITEM_TYPE_DRUG) //拖动行动快捷栏,目前只支持药品
//				{
//					var item:SkillsItem = SkillsItem(evt.target);
//					drageTarget.width = 37.5;
//					drageTarget.height = 37.5;
//					var matrix:Matrix = new Matrix(1, 0, 0, 1, -2.5, -2.5);
//					var bitmap:Bitmap = DisplayObjectCopy.copy(drageTarget, matrix);
//					item.removeIcon();
//					item.addIcon(bitmap);
//					vo.type = Enums.ITEM_TYPE_DRUG;
//					item.vo = vo;
//				}
//				else if (dropTarget != Element)
//				{
//					if (!(dropTarget == BackPackPanel))
//					{
//						//丢弃
//						switch (continerType)
//						{
//							case ElementContinerType.TYPE_BACKPACK_EQUIPMENT:
//							case ElementContinerType.TYPE_BACKPACK_DAOJU:
//							case ElementContinerType.TYPE_BACKPACK_BAOSHI://除了在锻造界面
//								var p:EquipForgingPanel = PanelManager.getInstance().getPanel(PanelType.EQUIP_FORGING_PANEL) as EquipForgingPanel;
//								if(!p || (p && !p.isOpen))
//								{
//									Alert.show("你确定要丢弃" + vo.name + "？", Alert.OK | Alert.CANCEL, throwOut);
//								}
//								break;
//						}
//					}
//				}
//				else
//				{
//					var targetElement:Element = evt.target as Element;
//					switch (targetElement.continerType)
//					{
//						case ElementContinerType.TYPE_USER_EQUIPMENT:
//						case ElementContinerType.TYPE_USER_WUQI:
//						case ElementContinerType.TYPE_USER_JINNANG:
//							if (continerType == ElementContinerType.TYPE_BACKPACK_EQUIPMENT)
//							{
//								if (targetElement.enabled && ItemType.checkIsEquipment(vo.type))//穿装备
//								{
//									//trace("穿上装备");
//									if (!wearEquipmentJudge(targetElement.vo))
//									{
//										break;
//									}
//									if(vo.type == Enums.ITEM_TYPE_SPECIAL)
//									{
//										switch(targetElement.index)
//										{
//											case 8:
//											case 9:
//											case 10:
//											case 11:
//												ItemProxy.getInstance().exChangeItem(vo.category, vo.index, targetElement.index);
//												break;
//										}
//									}
//									else if(ItemProxy.equipmentToType[vo.type] == targetElement.index)
//									{
//										ItemProxy.getInstance().exChangeItem(vo.category, vo.index, targetElement.index);
//									}
//								}
//							}
//							break;
//						case ElementContinerType.TYPE_BACKPACK_EQUIPMENT:
//							if (targetElement != null && drageProxy != null)//脱装备
//							{
//								if(targetElement.isLocking == false)
//								{
//									if(drageProxy.continerType && (drageProxy.continerType == ElementContinerType.TYPE_USER_EQUIPMENT || drageProxy.continerType == ElementContinerType.TYPE_USER_WUQI))
//										ItemProxy.getInstance().exChangeItem(drageProxy.category, drageProxy.index, targetElement.index);
//									else
//										ItemProxy.getInstance().exChangeItem(drageProxy.category, drageProxy.index, targetElement.index,true);
//								}
//							}
//							break;
//						/**装备强化*/
//						case ElementContinerType.TYPE_BACKPACK_TASK:
//						case ElementContinerType.TYPE_BACKPACK_DAOJU:
//						case ElementContinerType.TYPE_BACKPACK_BAOSHI:
//							ItemProxy.getInstance().exChangeItem(vo.category, vo.index, targetElement.index, true);
//							break;
//						case ElementContinerType.TYPE_EQUIP_STRENGTHEN_MAJOR:
//						case ElementContinerType.TYPE_EQUIP_STRENGTHEN_MINOR:
//						case ElementContinerType.TYPE_EQUIP_STRENGTHEN_INHERIT_MAJOR:
//						case ElementContinerType.TYPE_EQUIP_STRENGTHEN_INHERIT_MINOR:
//						case ElementContinerType.TYPE_EQUIP_REFINING_MAJOR:
//						case ElementContinerType.TYPE_EQUIP_REFINING_MINOR:
//						case ElementContinerType.TYPE_EQUIP_MOSAIC_MAJOR:
//						case ElementContinerType.TYPE_EQUIP_MOSAIC_MINOR:
//						case ElementContinerType.TYPE_EQUIP_MOSAIC_MINOR_SAVE:
//						case ElementContinerType.TYPE_EQUIP_COMPOSITION_INPUT:
//						case ElementContinerType.TYPE_EQUIP_COMPOSITION_OUTPUT:
//							if (continerType == ElementContinerType.TYPE_BACKPACK_EQUIPMENT
//								|| continerType == ElementContinerType.TYPE_BACKPACK_DAOJU
//								|| continerType == ElementContinerType.TYPE_BACKPACK_BAOSHI
//								|| continerType == ElementContinerType.TYPE_USER_EQUIPMENT
//								|| continerType == ElementContinerType.TYPE_USER_WUQI)
//							{
//								p = PanelManager.getInstance().getPanel(PanelType.EQUIP_FORGING_PANEL) as EquipForgingPanel;
//								if(targetElement.continerType != ElementContinerType.TYPE_EQUIP_STRENGTHEN_INHERIT_MAJOR
//									&& targetElement.continerType != ElementContinerType.TYPE_EQUIP_STRENGTHEN_INHERIT_MINOR)
//									p.fill(this);
//								else
//									p.fillEle(this, targetElement);
//							}
//							break;
//						case ElementContinerType.TYPE_PRECIOUS_COMPOSITION:
//							var e:EquipmentVo = this.vo as EquipmentVo;
//							if(!e || e.type != Enums.ITEM_TYPE_SPECIAL)/**非装备或非奇物*/
//								Alert.show('请放入奇物');
//							else if(e.bEquipped)/**装备中*/
//								Alert.show('请卸下该奇物');
//							else if(!e.compositions || e.compositions.length == 0)/**没有升级规则*/
//								Alert.show('该奇物不是一个可以升级的奇物');
//							else
//								targetElement.updateVo(this.vo);
//							break;
//					}
//				}
//				if (targetElement)
//				{
//					switch (targetElement.continerType)
//					{
//						case ElementContinerType.TYPE_BACKPACK_EQUIPMENT:
//						case ElementContinerType.TYPE_BACKPACK_DAOJU:
//						case ElementContinerType.TYPE_BACKPACK_BAOSHI:
//							p = PanelManager.getInstance().getPanel(PanelType.EQUIP_FORGING_PANEL) as EquipForgingPanel;
//							if(p)
//							{
//								p.unfill(this);
//							}
//							break;
//					}
//				}
//			}
			ElementDragManager.getInstance().clearDrag();
		}
		
		private function throwOut(result:int):void
		{
//			if (result == Alert.OK)
//			{
//				switch (continerType)
//				{
//					case ElementContinerType.TYPE_BACKPACK_EQUIPMENT:
//						//networkLogicProtocol.getInstance().requestDiscardEquip(vo.index);
//						break;
//					case ElementContinerType.TYPE_BACKPACK_DAOJU:
//						networkLogicProtocol.getInstance().requestDiscardItem(vo.index);
//						break;
//					case ElementContinerType.TYPE_BACKPACK_BAOSHI:
//						networkLogicProtocol.getInstance().requestDiscardGem(vo.index);
//						break;
//				}
//				ItemProxy.getInstance().throwOutItem(vo.category, vo.index);
//			}
		}

		public function get bg():DisplayObject
		{
			return _bg;
		}

		public function set bg(dis:DisplayObject):void
		{
			if (dis && _bg != dis)
			{
				_bg = dis;
				setBackgroundView(_bg);
			}
		}

		public function get fore():DisplayObject
		{
			return _fore;
		}

		public function set fore(dis:DisplayObject):void
		{
			if (dis && _fore != dis)
			{
				_fore = dis;
				setForegroundView(_fore);
				_fore.visible = false;
			}
		}

		override public function set width(value:Number):void
		{
			super.width = value;
		}

		override public function set height(value:Number):void
		{
			super.height = value;
		}

		public function set enabled(value:Boolean):void
		{
			if (_enabled == value)
			{
				return;
			}
			_enabled = value;
			if (value)
			{
				addEnabledListener();
			}
			else
			{
				removeEnabledListener();
			}
			addEventListener(MouseEvent.ROLL_OVER, onRollOverHandler, false, 0, true);
			addEventListener(MouseEvent.ROLL_OUT, onRollOutHandler, false, 0, true);
		}

		public function get enabled():Boolean
		{
			return _enabled;
		}
		
		private function onItemXmlLoaded(filename:String, data:Object, args:Object):void
		{
			var vo:BaseItemVo = args as BaseItemVo;
			var detial:XML = (data as XML).item.id[0];
			vo.icon = detial.@icon;
			vo.category = detial.@category;
			vo.capacity = detial.@capacity;
			vo.quality = detial.@quality;
			updateVo(vo);
		}

		public function updateVo(value:BaseItemVo):void
		{
			if (value != null && (value.category == Enums.ITEM_CATEGORY_ITEM || value.category == Enums.ITEM_CATEGORY_GEM || value.category == Enums.ITEM_CATEGORY_TASKITEM))
			{
				countLabel.visible = this.showCountLabel;
				if(value.capacity > 1)
				{
					countLabel.text = "" + value.count;
				}
				else
				{
					countLabel.text = "";
				}
			}
			else if(value != null && value.category == 0)/**只包含itemID的vo，先加载xml，然后再updateVo*/
			{
				ItemProxy.getInstance().getItemXML(value.itemId, onItemXmlLoaded, value);
				return;
			}
			else
			{
				countLabel.visible = false;
			}
			checkEnable(value);

			if (value == null)
			{
				if (icon.bitmapData)
				{
					icon.bitmapData = null;
				}
				if (vo)
				{
////					ResSystem.getInstance().unloadRes(GameConfig.m_ResConfig + ItemProxy.getInstance().byQualityGetURL(vo.quality,vo.icon));
//					ToolTipsManager.getInstance().cancelEquipComparison();
//					vo.tooltips = null;
				}
				vo = null;
				toolTips = null;
			}
			else
			{
				if (value == vo)
				{
					toolTips = vo.tooltips;
				}
				else
				{
					var getIcon:Boolean = false;
					if (!vo || vo.icon != value.icon)
					{
						icon.bitmapData = null;
						getIcon = true;
					}
					else
					{
						checkEnable(value);
					}
					vo = value;
					if (!vo.tooltips || vo.tooltips == "")
					{
						if (vo.category == Enums.ITEM_CATEGORY_EQUIPMENT) //装备
						{
							ItemProxy.getInstance().getBaseData(VoType.EQUIPMENT, vo.itemId, vo.index, vo, onToolTips, getIcon);
						}
						else if (vo.category == Enums.ITEM_CATEGORY_ITEM) //道具
						{
							ItemProxy.getInstance().getBaseData(VoType.DAOJU, vo.itemId, vo.index, vo, onToolTips, getIcon);
						}
						else if (vo.category == Enums.ITEM_CATEGORY_GEM) //宝石
						{
							ItemProxy.getInstance().getBaseData(VoType.BAOSHI, vo.itemId, vo.index, vo, onToolTips, getIcon);
						}
						else if (vo.category == Enums.ITEM_CATEGORY_TASKITEM) //任务道具
						{
							ItemProxy.getInstance().getBaseData(VoType.TASK, vo.itemId, vo.index, vo, onToolTips, getIcon);
						}
					}
					else
					{
						toolTips = vo.tooltips;
						ResSystem.getInstance().getRes(GameConfig.m_ResConfig + ItemProxy.getInstance().byQualityGetURL(vo.quality,vo.icon),setIcon);
					}
				}
			}
			dispatchEvent(new Event(Element.VO_CHANGE));
		}
		
		/**等待物品资源都加载完了，再检查是否达到条件*/
		private function checkEnable(value:BaseItemVo):void
		{
			if (enabledFunc != null)
			{
				enabled = enabledFunc(value);
			}
			bGray = !enabled;
		}
		
		/**
		 * 返回没有装备奇物下标
		 */
		public function getQiWuIndex():uint
		{
			var tempIndex:uint;

			var tempVO:BaseItemVo = ItemProxy.getInstance().getEquipmentVO(8);
			if (tempVO == null)
			{
				return tempIndex = 8;
			}
			else 
			{
				tempVO = ItemProxy.getInstance().getEquipmentVO(9);
				if(tempVO == null)
				{
					return tempIndex = 9;
				}
				else
				{
					tempVO = ItemProxy.getInstance().getEquipmentVO(10);
					if(tempVO == null)
					{
						return tempIndex = 10;
					}
					else
					{
						tempVO = ItemProxy.getInstance().getEquipmentVO(11);
						if(tempVO == null)
						{
							return tempIndex = 11;
						}
					}
				}
				return 8;
			}
		}

		private function onToolTips(id:int, getIcon:Boolean):void
		{
			if (!vo)
			{
				return;
			}
			if (id == vo.itemId)
			{
				toolTips = vo.tooltips;
			}
			if (vo != null && (vo.category == Enums.ITEM_CATEGORY_ITEM || vo.category == Enums.ITEM_CATEGORY_GEM || vo.category == Enums.ITEM_CATEGORY_TASKITEM))
			{
				countLabel.visible = this.showCountLabel;
				if(vo.capacity > 1)
				{
					countLabel.text = "" + vo.count;
				}
				else
				{
					countLabel.text = "";
				}
			}
			else
			{
				countLabel.visible = false;
			}
			if (getIcon)
			{
				ResSystem.getInstance().getRes(GameConfig.m_ResConfig + ItemProxy.getInstance().byQualityGetURL(vo.quality,vo.icon),setIcon);
			}
		}

		private function setIcon(str:String, obj:Object):void
		{
			if (!vo)
			{
				if (icon)
				{
					icon.bitmapData = null;
				}
			}
			else
			{
//				if ("/assets/" + ItemProxy.getInstance().byQualityGetURL(vo.quality,vo.icon) != str)
//				{
//					ResSystem.getInstance().unloadRes(GameConfig.m_ResConfig + ItemProxy.getInstance().byQualityGetURL(vo.quality,vo.icon));
//				}
//				else
//				{
					checkEnable(vo);
					icon.bitmapData = (obj as Bitmap).bitmapData;
					addChild(icon);
					this.addChildAt(countLabel, this.numChildren - 1);
//				}
			}
			if (okAlert)
			{
				dispatchEvent(new Event(Event.COMPLETE));
			}
		}

		/**
		 * 穿装备条件判断
		 * @param targetVO 目标VO
		 * @return true符合条件 false不符合条件
		 */
		private function wearEquipmentJudge(targetVO:BaseItemVo):Boolean
		{
			var result:Boolean = true;
//			if (targetVO == null)
//			{
//				return false;
//			}
//			if (targetVO.party == 1 || targetVO.party == 0)
//			{
//				result = true;
//			}
//			else
//			{
//				if (targetVO.party == PlayerAttribute.getInstance().m_CommonInfo._party && targetVO.party == vo.party)
//				{
//					result = true;
//				}
//				else
//				{
//					Alert.show("门派不符,无法装备");
//					return result = false;
//				}
//			}
//			if (PlayerAttribute.getInstance().m_CommonInfo._level >= targetVO.useLevel)
//			{
//				result = true;
//			}
//			else
//			{
//				Alert.show("等级不符,无法装备");
//				return result = false;
//			}
//			if (targetVO.type == vo.type)
//			{
//				result = true;
//			}
//			else
//			{
//				Alert.show("类型不符,无法装备");
//				return result = false;
//			}
			return result;
		}

		/**
		 * 出售物品
		 */
		private function sellHandler(result:int):void
		{
//			if (result == Alert.OK)
//			{
//				GlobalEventDispatcher.getInstance().dispatchEvent(new GlobalEvent(GlobalEvent.SELL_ITEM, vo));
//			}
		}

		/**----------------bGray------------------*/
		protected var grayFilter:Array;
		protected var _bGray:Boolean;

		public function set bGray(value:Boolean):void
		{
			if (_bGray != value)
			{
				_bGray = value
				if (icon)
					if (_bGray)
					{
						if (!grayFilter)
						{
							grayFilter = [new ColorMatrixFilter(FilterUtil.Gray)];
						}
						icon.filters = grayFilter;
					}
					else
						icon.filters = null;
			}
		}
		public var enabledFunc:Function;

		public function get index():int
		{
			return _index;
		}

		public function set index(value:int):void
		{
			_index = value;
			if(isStartUsing == true)
			{
				var count:uint;
				switch (continerType)
				{
					case ElementContinerType.TYPE_BACKPACK_EQUIPMENT:
						count = ItemProxy.getInstance().equipmentOpenCount + 20;
						break;
					case ElementContinerType.TYPE_BACKPACK_DAOJU:
						count = ItemProxy.getInstance().daoJuOpentCount;
						break;
					case ElementContinerType.TYPE_BACKPACK_BAOSHI:
						count = ItemProxy.getInstance().baoShiOpenCount;
						break;
					case ElementContinerType.TYPE_BACKPACK_TASK:
						count = ItemProxy.getInstance().taskOpenCount;
						break;
				}
				if (value >= count)
				{
					isLocking = true;
					this.addChild(lock);
				}
				else
				{
					isLocking = false;
					if (lock.parent != null)
					{
						lock.parent.removeChild(lock);
					}
				}
			}
		}

	}
}
